package net.kleinhenz.norabase.client;

import net.kleinhenz.norabase.client.datasource.CommentDS;
import net.kleinhenz.norabase.shared.model.Battlegroup;
import net.kleinhenz.norabase.shared.model.Comment;
import net.kleinhenz.norabase.shared.model.Rune;

import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridRecord;

public class RatingList extends ListGrid {

	private CommentDS datasource = null;;

	public RatingList() {
		setAutoFetchData(false);
		setShowHeader(false);		
		setWrapCells(true);
		setCellHeight(56); 
		setFixedRecordHeights(false); 
		setOverflow(Overflow.AUTO);
		setHeight("100%");
		setEmptyMessage("No comments yet.");
	}
	
	public void addRating(Comment entry) {
		ListGridRecord r = new ListGridRecord();
		CommentDS.copyValues(entry, r);
		addData(r);
	}
	
	public void loadRune(Rune rune) {
		datasource = new CommentDS(rune.getId(), Rune.typeToString(rune));			
		setDataSource(datasource);
		fetchData();
	}

	public void loadBattlegroup(Battlegroup<Rune> battlegroup) {
		datasource  = new CommentDS(battlegroup.getId());
		setDataSource(datasource);		
		fetchData();
	}
}
